
class SceneManager extends BaseClass {
    private _scenes: any;
    private _currScene: number;

    public constructor() {
        super();
        this._scenes = {}
        App.TimerManager.doFrame(1, 0, this.enterFrame, this);
    }

    private enterFrame(time: number) {
        let scene: BaseScene = this._scenes[this._currScene];
        if (scene) {
            scene.enterFrame(time)
        }
    }

    //清除所有的scene
    public clear(): void {
        var nowScene: BaseScene = this._scenes[this._currScene];
        if (nowScene) {
            nowScene.onExit();
            this._currScene = undefined;
        }
        this._scenes = {};
    }

    //注册一个scene
    public register(key: number, scene: BaseScene): void {
        this._scenes[key] = scene;
    }

    //切换场景
    public runScene(key: number, ...param: any[]): void {
        var nowScene: BaseScene = this._scenes[key];
        if (nowScene == null) {
            console.debug("场景" + key + "不存在");
            return;
        }
        var oldScene: BaseScene = this._scenes[this._currScene];
        if (oldScene) {
            oldScene.onExit();
        }

        //TODO: 这个是啥语法?
        nowScene.onEnter.apply(nowScene, param);

        this._currScene = key;
    }

    //获取当前Scene
    public getCurrScene(): number {
        return this._currScene;
    }
}